﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Daq.ViewModels.DeviceSettingsViewModels;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Telerik.Windows.Controls;

namespace Daq.ViewModels
{
    public class DeviceConfigStepInfo
    {
        public string Name { get; set; }
        public RadGlyph Icon { get; set; }
    }
    public partial class DeviceSettingsViewModel : ObservableObject
    {
        private readonly INavigationService _navigationService;
        public DeviceSettingsViewModel(INavigationService navigationService)
        {
            _navigationService = navigationService;
            _navigationService.CurrentViewModelChanged += () =>
            {
                CurrentViewModel = _navigationService.CurrentViewModel;
            };
            Steps = new ObservableCollection<StepInfo>
            {
                new StepInfo() { Text = "连接设置"},
                new StepInfo() { Text = "通道设置"},
                new StepInfo() { Text = "测量设置"},
                new StepInfo() { Text = "预处理设置"},
            };
        }

        [ObservableProperty]
        private ObservableObject? currentViewModel;


        public void SelectStep(string? step)
        {
            if (step == null) return;
            switch (step)
            {
                case "连接设置":
                    _navigationService.NavigateTo<ConnectionViewModel>();
                    break;
                case "通道设置":
                    _navigationService.NavigateTo<ChannelsViewModel>();
                    break;
                case "测量设置":
                    _navigationService.NavigateTo<MeasurementViewModel>();
                    break;
                case "预处理设置":
                    _navigationService.NavigateTo<DataPreprocessViewModel>();
                    break;
            }
            int index = 0;
            foreach (var s in Steps)
            {
                if (s.Text == step)
                {
                    SelectedIndex = index;
                    break;
                }
                index++;
            }
            //SelectedStep = Steps.FirstOrDefault(s => s.Text == step);
        }

        [RelayCommand]
        private void SelectStep(StepInfo step)
        {
            if (step == null) return;
            SelectStep(step.Text);
        }

        [ObservableProperty]
        private int selectedIndex;

        public ObservableCollection<StepInfo> Steps { get; set; }
    }

    public class StepInfo
    {
        public string? Text { get; set; }
        public string? AdditionalText { get; set; }
    }

}
